//
//  CSViewController.m
//  CSDatabase
//
//  Created by hcsaaron@163.com on 06/14/2021.
//  Copyright (c) 2021 hcsaaron@163.com. All rights reserved.
//

#import "CSViewController.h"
#import <CSDatabase/CSDatabase.h>
#import "CSPerson.h"

@interface CSViewController ()

@end

@implementation CSViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    CSDatabase *database = [CSDatabase defaultDatabase];
    
    BOOL success = [database createTable:@"Person" withModelClass:[CSPerson class]];
    NSLog(@"create success = %d", success);

    CSPerson *person = [[CSPerson alloc] init];
    person.name = @"Aaron";
    person.sex = @"Boy";
    person.height = 175;
    
    success = [database insertIntoTable:@"Person" withModel:person];
    NSLog(@"inser success = %d", success);
    
    person.height = 172;
    success = [database updateFromTable:@"Person" withModel:person whereFormat:@""];
    NSLog(@"update success = %d", success);
    
    NSArray *array = [database queryFromTable:@"Person" withModelClass:[CSPerson class] whereFormat:@""];
    NSLog(@"query array = %@", array);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
